package com.dc.refactoring._3_重新组织数据._11_ReplaceTypeCodeWithClass.step2;

public class Person {

    // 【6】把 Person 中的类型码改为 BloodGroup类
    public static int O = BloodGroup.O.getCode();
    public static int A = BloodGroup.A.getCode();
    public static int B = BloodGroup.B.getCode();
    public static int AB = BloodGroup.AB.getCode();

    // 【7】修改 bloodGroup 的引用，及设置函数、取值函数
    //private int bloodGroup;
    private BloodGroup bloodGroup;

    public Person(int bloodGroup){
        //this.bloodGroup = bloodGroup;
        this.bloodGroup = BloodGroup.code(bloodGroup);
    }

    public int getBloodGroup() {
        //return bloodGroup;
        return bloodGroup.getCode();
    }

    public void setBloodGroup(int bloodGroup) {
        //this.bloodGroup = bloodGroup;
        this.bloodGroup = BloodGroup.code(bloodGroup);
    }


    // 【9】可以创建新的构造函数和设置函数
    public Person(BloodGroup bloodGroup) {
        this.bloodGroup = bloodGroup;
    }

    public void setBloodGroup(BloodGroup bloodGroup){
        this.bloodGroup = bloodGroup;
    }
}
